#include "StdAfx.h"
#include "IplImageDraw.h"
#include "OpenCV2CXimage.h"


BITMAPINFOHEADER   CIplImageDraw::bmi; 

CIplImageDraw::CIplImageDraw(void)
{
}


CIplImageDraw::~CIplImageDraw(void)
{
}

void CIplImageDraw::ShowIplImageToHDC(CDC * pDC,IplImage *src)
{
	OpenCV2CXimage opencvimage;
	CxImage image;
	opencvimage.IplImage2Cximage(src,&image,src->depth);
	image.Draw(pDC->GetSafeHdc(),CRect(0,0,src->width,src->height));

 //   bmi.biSize   =   sizeof(BITMAPINFOHEADER); 
 //   bmi.biWidth   =   src->width; 
 //   bmi.biHeight   =   src->height; 
 //   bmi.biPlanes   =   1; 
 //   bmi.biBitCount   =   32; 
 //   bmi.biCompression   =   BI_RGB; 
 //   bmi.biSizeImage   =   0; 
 //   bmi.biXPelsPerMeter   =   0; 
 //   bmi.biYPelsPerMeter   =   0; 
 //   bmi.biClrUsed   =   0; 
 //   bmi.biClrImportant   =   0; 

	//if(src->nChannels==3)// color
	//{  
	//	IplImage * TheImage=cvCloneImage(src);
	//	CvSize ImgSize;
	//	ImgSize.width = TheImage->width;
	//	ImgSize.height = TheImage->height;
	//	int res = StretchDIBits(pDC->GetSafeHdc(),0,0,int(TheImage->width),int(TheImage->height),
	//	0,0,TheImage->width,TheImage->height,TheImage->imageData,
	//	(LPBITMAPINFO)&bmi,DIB_RGB_COLORS,SRCCOPY);
	//}
	//else
	//{
	//	if(src->nChannels==1)// gray
	//	{   
	//		IplImage *grayImg=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,3);
	//		IplImage * planes[3] ={0,0,0};
	//		for(int i=0;i<3;i++)
	//		{
	//			planes[i] = cvCreateImage(cvSize(src->width,src->height),8,1);
	//			(planes[i]->imageData)= (src->imageData);
	//		}
	//		cvCvtPlaneToPix(planes[0],planes[1],planes[2],0,grayImg);
	//		IplImage * TheImage=cvCloneImage(grayImg);
	//		CvSize ImgSize;
	//		ImgSize.width = TheImage->width;
	//		ImgSize.height = TheImage->height;
	//		int res = StretchDIBits(pDC->GetSafeHdc(),0,0,int(TheImage->width),int(TheImage->height),
	//		0,0,TheImage->width,TheImage->height,TheImage->imageData,
	//		(LPBITMAPINFO)&bmi,DIB_RGB_COLORS,SRCCOPY);
	//	}
	//}
}